﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Omnia.Enums;
using Microsoft.Phone.Tasks;

namespace Omnia.UX
{
    public class UXHyperLink : Button
    {
        public UXHyperLink()
        {
            DefaultStyleKey = typeof(UXHyperLink);
            Click += new RoutedEventHandler(UXHyperLink_Click);
        }

        void UXHyperLink_Click(object sender, RoutedEventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(UrlOrNumber))
            {
                switch (LinkType)
                {
                    case LinkTypeValue.Url:
                        WebBrowserTask web = new WebBrowserTask();
                        web.URL = UrlOrNumber;
                        web.Show();
                        break;
                    case LinkTypeValue.Email:
                        EmailComposeTask email = new EmailComposeTask();
                        email.To = UrlOrNumber;
                        email.Show();
                        break;
                    case LinkTypeValue.Phone:
                        PhoneCallTask phone = new PhoneCallTask();
                        phone.PhoneNumber = UrlOrNumber;
                        phone.Show();
                        break;
                    case LinkTypeValue.Sms:
                        SmsComposeTask sms = new SmsComposeTask();
                        sms.To = UrlOrNumber;
                        sms.Show();
                        break;
                    default: break;
                }
            }
        }

        public string UrlOrNumber
        {
            get { return GetValue(UrlOrNumberProperty) as string; }
            set
            {
                SetValue(UrlOrNumberProperty, value);
            }
        }

        public static readonly DependencyProperty UrlOrNumberProperty = DependencyProperty.Register(
            "LinkType",
            typeof(string),
            typeof(UXHyperLink),
            new PropertyMetadata(null));

        public LinkTypeValue LinkType
        {
            get { return (LinkTypeValue)GetValue(LinkTypeProperty); }
            set
            {
                SetValue(LinkTypeProperty, value);
            }
        }

        public static readonly DependencyProperty LinkTypeProperty = DependencyProperty.Register(
            "LinkType",
            typeof(LinkTypeValue),
            typeof(UXHyperLink),
            new PropertyMetadata(LinkTypeValue.Url));
    }
}
